{extend name="indexextends"}



{block name="title"}项目设置{/block}

{block name='project'}layui-this{/block}


{block name='nr'}





<div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
    <ul class="layui-tab-title">
        <li class="layui-this">项目配置</li>
        <li>项目信息</li>
        <li>百度接口</li>
    </ul>
    <div class="layui-tab-content">
        <!--项目配置-->
        <div class="layui-tab-item layui-show">

                <div style="padding: 30px;">
                    <p style="color: red"><i class="layui-icon" style="color: red">&#xe702;</i>警告：使用Easycms前请先完整的填写配置信息</p>
                    <br>
                    <p>若你的cms系统安装在站点根目录，那么假如你域名为www.aaa.com，如果想选择根目录的www.aaa.com/index.html作为主页路径，那么就填写../</p>
                    <br>
                    <p>此处设置的<span style="color: red">根目录路径</span>，后续发布文章时上传的图片都会保存在根目录下uploadImg文件中</p>
                    <br>
                    <p>主页模板名称默认为<span style="color: red">index.html</span>，如若需要修改，在此处修改名称之后需手动修改<span style="color: red">\cms\public\static\templets</span>目录下的文件名称</p>
                    <br>
                    <p>项目文件夹名称默认为<span style="color: red">cms</span></p>
                </div>




            <form class="layui-form" id="project_form" method="post">

                <div class="layui-form-item">
                    <label class="layui-form-label" style="width: 100px">项目域名</label>
                    <div class="layui-input-inline">
                        <input type="text" name="domain_name" required lay-verify="required" placeholder="例如：https://www.xxx.com" autocomplete="off" class="layui-input" value="{$domain_name}">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label" style="width: 100px">项目路径</label>
                    <div class="layui-input-inline">
                        <input type="hidden" name="id"  value="{$id}">
                        <input type="text" name="homepath" required lay-verify="required" placeholder="请输入项目路径" autocomplete="off" class="layui-input" value="{$homepath}">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label" style="width: 100px">主页模板名称</label>
                    <div class="layui-input-inline">
                        <input type="text" name="filename" required lay-verify="required" placeholder="请输入项目路径" autocomplete="off" class="layui-input" value="{$filename}">
                    </div>
                </div>


                <div class="layui-form-item">
                    <label class="layui-form-label" style="width: 100px">项目文件夹名称</label>
                    <div class="layui-input-inline">
                        <input type="text" name="projectname" required lay-verify="required" placeholder="请输入项目路径" autocomplete="off" class="layui-input" value="{$projectname}">
                    </div>
                </div>


                <div class="layui-form-item">
                    <label class="layui-form-label" style="width: 100px">文章文件夹名称</label>
                    <div class="layui-input-inline">
                        <input type="text" name="art_dir_name" required lay-verify="required" placeholder="请输入项目路径" autocomplete="off" class="layui-input" value="{$art_dir_name}">
                    </div>
                </div>

                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <input type="button" class="layui-btn" value="保存" onclick="save()">
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </div>
            </form>
        </div>

        <!--项目信息-->
        <div class="layui-tab-item">

            <form  enctype="multipart/form-data" method="post" class="layui-form"  id="forms" >

                <div class="layui-form-item" >
                    <label class="layui-form-label" >项目名称</label>
                    <div class="layui-input-inline"  >
                        <input type="text" name="name" id="name" lay-verify="title" autocomplete="off"  class="layui-input">
                        <input type="hidden" name="id"  id="id">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label" >Logo</label>
                    <div class="layui-upload" >
                        <button type="button" class="layui-btn" id="test2">上传图片</button>
                        <input type="hidden" name="logo" id="logo">
                        <div class="layui-upload-list" style="margin-left: 7%">
                            <img class="layui-upload-img" id="img" style="width: 10%" >
                            <p id="demoText" ></p>
                        </div>

                        <div style="width: 95px;margin-left: 7%">
                            <div class="layui-progress layui-progress-big" lay-showpercent="yes" lay-filter="demo">
                                <div class="layui-progress-bar" lay-percent=""></div>
                            </div>
                        </div>


                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label" >ICP备案信息</label>
                    <div class="layui-input-inline" >
                        <input type="text" name="icp" id="icp" lay-verify="title" autocomplete="off"  class="layui-input" >
                    </div>
                </div>

                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label" >统计代码</label>
                    <div class="layui-input-block" >
                        <textarea name="tj" id="tj"  class="layui-textarea" ></textarea>
                    </div>
                </div>

                <input type="button" value="保存" onclick="save2()" class="layui-btn" style="margin-left: 10%">
            </form>

        </div>

        <!--百度接口-->
        <div class="layui-tab-item">
            <div style="padding: 30px;">
                <p style="color: red"><i class="layui-icon" style="color: red">&#xe702;</i>此功能请配合百度站长使用https://ziyuan.baidu.com/</p>

            </div>

            <form method="post" class="layui-form" id="Db_api_form">

                <div class="layui-form-item" >
                    <label class="layui-form-label" >百度token</label>
                    <div class="layui-input-inline"  >
                        <input type="text" name="token"  lay-verify="title" autocomplete="off"  class="layui-input" id="token">
                        <input type="hidden" name="id" value="1">
                    </div>
                </div>


                <input type="button" value="保存" onclick="save3()" class="layui-btn" style="margin-left: 10%">
            </form>

        </div>
    </div>
</div>


{/block}

{block name='js'}

<script>


    //logo上传
    layui.use(['upload', 'element', 'layer'], function() {
        var $ = layui.jquery
            , upload = layui.upload
            , element = layui.element
            , layer = layui.layer;



        var uploadInst = upload.render({
            size:2048
            ,elem: '#test2'
            ,url: '{:url("admin/project/Upload_logo")}' //此处用的是第三方的 http 请求演示，实际使用时改成您自己的上传接口即可。
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#img').attr('src', result); //图片链接（base64）
                });

                element.progress('demo', '0%'); //进度条复位
                layer.msg('上传中', {icon: 16, time: 0});
            }
            ,done: function(res){
                //如果上传失败
                if(res.code > 0){
                    return layer.msg('上传失败');
                }
                //上传成功的一些操作
                //……
                $('#demoText').html(''); //置空上传失败的状态

                $("#logo").val(res.data.src)//将隐藏域的value值设置为缩略图的url，便于表单提交
            }
            ,error: function(){
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadInst.upload();
                });
            }
            //进度条
            ,progress: function(n, elem, e){
                element.progress('demo', n + '%'); //可配合 layui 进度条元素使用
                if(n == 100){
                    layer.msg('上传完毕', {icon: 1});
                }
            }
        });


    });


    //项目信息保存
    function save2() {
        $("#forms").ajaxSubmit({
            url:"{:url('admin/project/set_proinfo')}",
            success:function (res) {
                res=$.parseJSON(res);
                layer.msg(res)
            }


        })


    }

    //选项卡切换事件
    layui.use('element', function(){
        var $ = layui.jquery
            ,element = layui.element; //Tab的切换功能，切换事件监听等，需要依赖element模块

        element.on('tab(docDemoTabBrief)', function(data){
            // console.log(data.index); //得到当前Tab的所在下标
           if (data.index==1){
               //点到下标为1时，也就是项目信息，那么开始渲染项目信息的数据
               $.ajax({
                   url:"{:url('admin/project/show_proinfo')}",
                   type:"POST",
                   success:function (res) {
                       res=$.parseJSON(res)
                       var id=res['id']
                      var pj_name=res['pj_name']
                      var tj=res['tj']
                      var logo=res['logo']
                      var icp=res['icp']


                       $('#img').attr('src',logo); //图片链接（base64）
                       $("#name").attr('value',pj_name)
                       $("#id").attr('value',id)
                       if (tj!=null){
                           $("#tj").text(tj)
                       }

                       $("#icp").attr('value',icp)



                   }


               })

           }else if (data.index==2){
               //点到下标为2时，也就是百度api，那么开始渲染项目信息的数据

               $.ajax({
                   url:"{:url('admin/project/show_bd')}",
                   type:"POST",
                   success:function (res) {
                       res=$.parseJSON(res)
                       var token=res['token']

                       $("#token").attr('value',token)




                   }


               })
           }


        });

    });


    //项目配置保存
    function save(){

       $("#project_form").ajaxSubmit({
           url:"{:url('admin/project/editConfig')}",
           type:"POST",
           success:function (res) {
               res=$.parseJSON(res);
               layer.msg(res['message'])
           }
       })
    }

    //项目配置保存
    function save3(){

        $("#Db_api_form").ajaxSubmit({
            url:"{:url('admin/project/bd_editConfig')}",
            type:"POST",
            success:function (res) {
                res=$.parseJSON(res);
                layer.msg(res)
            }
        })
    }



    //主页更新
    function update(){
        $.ajax({
            url:"{:url('admin/project/updateHomePage')}",
            type:"POST",
            success:function (res) {
                res=$.parseJSON(res)
                layer.msg(res)
            }


        })

    };

    //清除缓存
    function clean(){
        $.ajax({
            url:"{:url('admin/project/cache_clear')}",
            type:"POST",
            success:function (res) {
                res=$.parseJSON(res)
                layer.msg(res)
            }


        })

    }



</script>


{/block}